package main.java.FSMDE.validation.rules;

import java.util.ArrayList;
import java.util.List;

import main.java.FSMDE.models.Diagram;
import main.java.FSMDE.models.Interface;
import main.java.FSMDE.models.InterfaceGraphType;
import main.java.FSMDE.validation.IValidationEntry;
import main.java.FSMDE.validation.rules.IRulesValidator;


public class DiagramMustHaveInterfacesValidator implements IRulesValidator {

	@Override
	public Iterable<IValidationEntry> validate(Diagram diagram) {
		int start = 0;
		int end = 0;
		int count = 0;
		List<IValidationEntry> entries = new ArrayList<IValidationEntry>();
		for (Interface fsminface : diagram.getInterfaces()) {
			if(fsminface.getGraphType().equals(InterfaceGraphType.Starting_interface) ){
				start++;
			}
			if(fsminface.getGraphType().equals(InterfaceGraphType.Ending_interface)){
				end++;
			}
			count++;
		}
		if(count == start+end && count != 0){
			entries.add(new DiagramMustHaveInterfacesValidationEntry(diagram));
		}
		if(count == 0) entries.add(new DiagramHasNoInterfacesValidationEntry(diagram));
		return entries;
	}

}
